package com.lccviolet;

/**
 * @author LiChaochao
 * @Date 2021/10/7 9:51
 * @Description 字符串常量池，“java”字段
 */
public class StringPoolDemo {

    public static void main(String[] args) {
        String str1 = new StringBuilder("58").append("tongcheng").toString();
        System.out.println(str1); //58tongcheng
        System.out.println(str1.intern()); //58tongcheng
        System.out.println(str1 == str1.intern()); //true

        System.out.println("=========================");

        String str2 = new StringBuilder("ja").append("va").toString();
        System.out.println(str2); //java
        System.out.println(str2.intern()); //java
        System.out.println(str2 == str2.intern()); //false
    }
}
